import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_syt/datas/message_model.dart';
import 'package:flutter_syt/utils/utils_dlog.dart';
import 'package:flutter_syt/utils/web_socket_utility.dart';

class WebSocketTestPage extends StatefulWidget {
  @override
  WebSocketTestPageState createState() => WebSocketTestPageState();
}

class WebSocketTestPageState extends State<WebSocketTestPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('sports'),
      ),
      body: Column(
        children: [
          Row(
            children: [Expanded(child: Container()), Container()],
          ),
          // Expanded(child: pagev)
        ],
      ),
    );
    // return Scaffold(
    //   appBar: AppBar(
    //     title: Text(''),
    //   ),
    //   body: Column(
    //     children: [
    //       SizedBox(
    //         height: 10,
    //         width: 1.sw,
    //       ),
    //       GestureDetector(
    //         onTap: () {
    //           // WebSocketUtility.instance.initWebSocket(onOpen: () {
    //           //   DLog('连接成');
    //           // }, onMessage: (data) {
    //           //   DLog('接收到消息$data');
    //           // }, onError: (error) {
    //           //   DLog('连接失败 $error');
    //           // });
    //           // WebSocketUtility.instance.openSocket();
    //         },
    //         behavior: HitTestBehavior.opaque,
    //         child: Container(
    //           height: 50,
    //           width: 100,
    //           decoration:
    //               BoxDecoration(border: Border.all(color: Colors.black26)),
    //           child: Text('连接websocket'),
    //         ),
    //       ),
    //       GestureDetector(
    //         onTap: () {
    //           WebSocketUtility.instance.closeSocket();

    //           // WebSocketUtility.instance.openSocket();
    //         },
    //         behavior: HitTestBehavior.opaque,
    //         child: Container(
    //           margin: EdgeInsets.only(top: 20),
    //           height: 50,
    //           width: 100,
    //           decoration:
    //               BoxDecoration(border: Border.all(color: Colors.black26)),
    //           child: Text('断开连接websocket'),
    //         ),
    //       ),
    //       GestureDetector(
    //         onTap: () {
    //           MessageModel model = MessageModel(
    //             type: 10,
    //             msgType: 1,
    //             content: "test",
    //             picUrl:
    //                 "https://smart-pic.oss-cn-hangzhou.aliyuncs.com/9234/89e6/923489e6ac293eebde81b9cd505553df.jpg",
    //           );
    //           WebSocketUtility.instance.sendMessage(model);

    //           // WebSocketUtility.instance.openSocket();
    //         },
    //         behavior: HitTestBehavior.opaque,
    //         child: Container(
    //           margin: EdgeInsets.only(top: 20),
    //           height: 50,
    //           width: 100,
    //           decoration:
    //               BoxDecoration(border: Border.all(color: Colors.black26)),
    //           child: Text('发送消息'),
    //         ),
    //       )
    //     ],
    //   ),
    // );
  }

  @override
  void initState() {
    super.initState();
    // DateTime.now().isAfter(other)
    // Duration date =   DateTime.now().difference(other)
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  void didUpdateWidget(WebSocketTestPage oldWidget) {
    super.didUpdateWidget(oldWidget);
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
  }
}
